Skip to content

test: fix flaky tests by replacing hardcoded sleeps with polls - #263

Merged
imor merged 3 commits into
masterfrom
test/fix-flaky-tests
Aug 5, 2026
Merged

test: fix flaky tests by replacing hardcoded sleeps with polls#263
imor merged 3 commits into
masterfrom
test/fix-flaky-tests

Conversation

@imor

@imor imor commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This PR started off as an attempt to fix flaky tests but has grown into a mini overhaul of the tests. The changes include:

  • Fixed many causes of flakiness, including hardcoded time.sleep(...) calls and race conditions and assumptions in the test code. The improvement is evidenced in the last 12 or so commits in this PR. Before this PR, the tests would fail quite often. Examples: one, two, three, four, and many more. The new code waits for certain events to happen instead of hardcoded timeouts which is more robust.
  • Made the code more readable by factoring out common code into common.py which also makes test smaller and easier to read.
  • Removed some commented out code.
  • Moved cleanup logic in tests into finally blocks to ensure one failing tests doesn't make other tests fail, improving test isolation.
  • Formatted the code according to python standards.
  • Added support for running a subset of tests locally during development. Updated CONTRIBUTING.md to show how to run a single or a subset of tests.
  • Made sure on pushing a commit to a PR branch only one set of tests run. Previously two sets of tests would run in this case. Merging into master still triggers a separate test run.

Further improvement planned in a separate PR: currently test on each PG version unnecessarily pulls in all PG versions in nix store via xpg. This is ~700 MB worth of data pulled from the cache. This can be reduced if a single test could only copy that specific version of PG.

@imor
imor force-pushed the test/fix-flaky-tests branch from 8fce899 to 1732c88 Compare July 30, 2026 13:41
@imor
imor marked this pull request as ready for review July 31, 2026 17:34
@imor
imor requested a review from steve-chavez July 31, 2026 17:34
Comment thread test/common.py

@steve-chavez steve-chavez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM.

Formatted the code according to python standards.

Note: to make reviewing easier is better to do linting on a separate PR. It should also be enforced on CI.

@steve-chavez

steve-chavez commented Aug 4, 2026

Copy link
Copy Markdown
Member

The commits here are not looking that good for git history -- critical for when a bug arises on prod.

Also a64f20d is labeled as refactor: but it really is a test: (because it doesn't change core logic).

It looks to me all of these can be squashed onto 3 commits:

  • test: ...
  • docs: ...
  • ci: ...

@imor Before merging, could you do that? 🙏

Edit: Non-blocking request, but would be good to have. Feel free to merge if you disagree.

@imor

imor commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

The commits here are not looking that good for git history -- critical for when a bug arises on prod.

Also a64f20d is labeled as refactor: but it really is a test: (because it doesn't change core logic).

It looks to me all of these can be squashed onto 3 commits:

  • test: ...
  • docs: ...
  • ci: ...

@imor Before merging, could you do that? 🙏

Edit: Non-blocking request, but would be good to have. Feel free to merge if you disagree.

No worries, will rewrite into a cleaner history @steve-chavez. I know this was not the easiest of PRs to review so thanks for you time 🙏🏼

imor added 3 commits August 5, 2026 09:32
Instead of using sleeps in tests which assumed that certain operations will
complete within those timeouts, we now poll for events to ensure that tests pass
deterministically everywhere: locally and in ci. Before this change the tests
would pass locally but will fail in ci. Such flaky tests make it hard to make
changes in the code because the confidence in the tests went down and developers
could dismiss genuine failures due to alert fatigue.
We no longer download all PG versions to reduce CI time. xpg 2.5.0 added support
for downloading only one PG version. We bumped to xpg 2.5.0 to use this feature
and updated commands in CI to use this feature.

We also avoid running two workflows on push to a PR branch. The on: [push,
pull_request] ran two duplicate workflows for each push to a PR branch.  This
was wasteful. Now we only run one workflow for each push to a PR branch. We also
run a workflow once commits land on the master branch, e.g.  after a PR is
merged.
@imor
imor force-pushed the test/fix-flaky-tests branch from ca6b6ec to fcb0717 Compare August 5, 2026 04:19
@imor
imor merged commit 35907eb into master Aug 5, 2026
20 checks passed
@imor
imor deleted the test/fix-flaky-tests branch August 5, 2026 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants